/*================================================================
*   Copyright (C) 2020 belonging to YangZhengQing. All rights reserved.
*   
*   文件名称：type.c
*   创 建 者：YangZhengQing
*   创建日期：2020年03月03日
*   描    述：字节转整型、整型转字节
*
*================================================================*/

#include <stdio.h>
#include "../include/client.h"


/*
功能：int 转 byte
参数：
	byte：字节数组
	number：整型数据
*/
void to_bytes(unsigned char *bytes, int number)
{
	//低位在前
	bytes[0] = (unsigned char)number;
	bytes[1] = (unsigned char) (number >> 8);
	bytes[2] = (unsigned char) (number >> 16);
	bytes[3] = (unsigned char) (number >> 24);
}


/*
   功能：byte 转 int
   参数：
	bytes：字节数组
   返回：整型
*/

int to_int(unsigned char *bytes)
{
	int value = 0;

	value = ((bytes[3] & 0xff)<<24)|
			((bytes[2] & 0xff)<<16)|
			((bytes[1] & 0xff)<<8)|
			(bytes[0] & 0xff);
	
	return value;
}



